home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
tex
/
gestalt.zip
/
GESTALT.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1988-12-06
|
3KB
|
102 lines
PROGRAM TestSim;
{Test SIMIL_P.ASM string similarity function.
See SIMIL_C.ASM for detailed explanation,
or look at the original article in Dr. Dobbs Journal.
(You mean, you don't subscribe to Dr. Dobbs? Sigh ...)
Works just fine with Turbo Pascal v3.0.
I don't HAVE v4.0, etc., so you're on your own if you want
to port it.
David Kirschbaum
Toad Hall
kirsch@braggvax.ARPA
}
{ Simil procedure requires these internally:}
TYPE
array25 = ARRAY[1..25] OF INTEGER;
VAR
ststr1L,
ststr1R,
ststr2L,
ststr2R : array25;
stcknum,
score,
total,
cL1,
cR1,
cL2,
cR2,
s2ed : INTEGER;
FUNCTION Simil (VAR Str1, Str2) : INTEGER;
{We're assuming Str1 and Str2 are in fact Pascal strings.
Type is immaterial, just so long as the first byte is the length byte.
}
VAR result : INTEGER;
BEGIN
{$I SIMIL_P.OBJ}
Simil := result; {return function}
END; {of Simil}
{Test program needs this for passing parms, etc.}
TYPE
Str128 = STRING[128];
{Show that Simil will work with passed variables.
(This works just as well if you use (VAR S21,S22 : Str128).
}
PROCEDURE Do_Simil_Var(S21,S22 : Str128);
VAR
i : INTEGER;
BEGIN
Writeln('Testing Simil function with passed variables...');
S21 := '[20char test string]';
S22 := S21;
FOR i := 1 TO LENGTH(S21) DO BEGIN
Writeln(S21, S22, ' Similarity: ', Simil(S21,S22):3, '%');
S22[i] := '.'; {blank out a char in String 2}
END;
Writeln(S21, S22, ' Similarity: ', Simil(S21,S22):3, '%');
END; {of Do_Simil_Var}
{Show that Simil will work with local variables as well as globals}
PROCEDURE Do_Simil_Local;
VAR
S31,S32 : Str128;
i : INTEGER;
BEGIN
Writeln('Testing Simil function with local variables...');
S31 := '[20char test string]';
S32 := S31;
FOR i := 1 TO LENGTH(S31) DO BEGIN
Writeln(S31, S32, ' Similarity: ', Simil(S31,S32):3, '%');
S32[i] := '.'; {blank out a char in String 2}
END;
Writeln(S31, S32, ' Similarity: ', Simil(S31,S32):3, '%');
END; {of Do_Simil_Local}
{Required for our test program}
VAR
S1,S2 : Str128;
i : INTEGER;
BEGIN {main}
Writeln('Testing Simil function with global variables...');
S1 := '[20char test string]';
S2 := S1;
FOR i := 1 TO LENGTH(S1) DO BEGIN
Writeln(S1, S2, ' Similarity: ', Simil(S1,S2):3, '%');
S2[i] := '.'; {blank out a char in String 2}
END;
Writeln(S1, S2, ' Similarity: ', Simil(S1,S2):3, '%');
Do_Simil_Var(S1,S2); {Test Simil with passed variables}
Do_Simil_Local; {Test Simil with local variables}
END.